<?php
	//----------------------- INPUT ELEMENTS -------------------//
	$name 			= $this->formText ('name', $this->Item['name'], array ('class' => 'txtmedium') ) . '<div class="view_error" id="view_name"></div>';
	$tenviettat 	= $this->formText ('tenviettat', $this->Item['tenviettat'], array ('class' => 'txtmedium') );
	
	$optionTiemnang		= array(
							'0' => 'Tổ chức không theo dõi',
							'1' => 'Tổ chức tiềm năng'
						);
	$status_tiemnang		= 0;
	if(isset($this->arrParam['tn'])){
		$status_tiemnang	= $this->arrParam['tn'];
	}
	$status_tiemnang		= $this->formSelect('status_tiemnang', $status_tiemnang, array('style'=>'width:256px;'), $optionTiemnang);
	
	$country = 0;
	if (!empty($this->Item['id_country'])) {
		$country = $this->Item['id_country'];
	}
	$city = 0;
	if (!empty($this->Item['id_city'])) {
		$city = $this->Item['id_city'];
	}
	$district = 0;
	if (!empty($this->Item['id_district'])) {
		$district = $this->Item['id_district'];
	}
	$id_phongban = 0;
	if (!empty($this->Item['id_phongban'])) {
		$id_phongban = $this->Item['id_phongban'];
	}
	$id_phongbans = $id_phongban;

	$nhanvien = 0;
	if (!empty($this->Item['id_nhanvien'])) {
		$nhanvien = $this->Item['id_nhanvien'];
	}
	
	$note 					= $this->formTextarea('note', $this->Item['note'], array ('class' => 'textarea', 'rows' => '2') );
	$masothue 				= $this->formText ('masothue', $this->Item['masothue'], array ('class' => 'txtmedium') );
	$namthanhlap 			= $this->formText ('namthanhlap', $this->Item['namthanhlap'], array ('class' => 'txtmedium') );
	$sodkkd 				= $this->formText ('sodkkd', $this->Item['sodkkd'], array ('class' => 'txtmedium') );
	$ngaykiniem 			= $this->formText ('ngaykiniem', $this->Item['ngaykiniem'], array ('class' => 'txtmedium hasDatePicker', 'title' => 'Ngày / tháng / năm') );
	$tongsolaodong			= $this->formText ('tongsolaodong', $this->Item['tongsolaodong'], array ('class' => 'txtmedium') );
	$telephone				= $this->formText ('telephone', $this->Item['telephone'], array ('class' => 'txtmedium') );
	$address				= $this->formText ('address', $this->Item['address'], array ('class' => 'txtmedium') );
	$fax					= $this->formText ('fax', $this->Item['fax'], array ('class' => 'txtmedium') );
	$email					= $this->formText ('email', $this->Item['email'], array ('class' => 'txtmedium') );
	$website 				= $this->formText ('website', $this->Item['website'], array ('class' => 'txtmedium') );
	$ghichu					= $this->formTextarea('ghichu', $this->Item['ghichu'], array ('style'=>'width:248px;', 'rows' => '2') );
	$phone					= $this->formText ('phone', $this->Item['phone'], array ('class' => 'txtmedium') );
	$created				= $this->formText ('created', $this->Item['created'], array('class' => 'txtmedium', 'disabled' => 'disabled'));
	$created_by				= $this->formText ('created_by', $this->createdBy['name'], array('class' => 'txtmedium', 'disabled' => 'disabled'));
	$modified				= $this->formText ('modified', $this->Item['modified'], array('class' => 'txtmedium', 'disabled' => 'disabled'));
	$modified_by			= $this->formText ('modified_by', $this->modifiedBy['name'], array('class' => 'txtmedium', 'disabled' => 'disabled'));
	$id_country  			= $this->formSelect('id_country',$this->Item['id_country'], array('style'=>'width:256px;', 'onChange' => 'show_cities(' . $country . ', '. $city .', '. $district .')'), $this->slbCountries);
	$id_city  				= $this->formSelect('id_city',$this->Item['id_city'], array('style'=>'width:256px;', 'onChange' => 'show_districts(' . $country . ', '. $city .', '. $district .')'), $this->slbCities);
	$id_district  			= $this->formSelect('id_district',$this->Item['id_district'], array('style'=>'width:256px;'), $this->slbDistricts);
	$id_nguon  				= $this->formSelect('id_nguon',$this->Item['id_nguon'], array('style'=>'width:256px;'), $this->slbNguonKH);
	$id_nguon_dk  			= $this->formSelect('id_nguon_dk',$this->Item['id_nguon_dk'], array('style'=>'width:256px;'), $this->slbNguonKHDK);
	$id_tinhtrang  			= $this->formSelect('id_tinhtrang',$this->Item['id_tinhtrang'], array('style'=>'width:256px;'), $this->slbTinhTrangKH);
	$id_quymocongty			= $this->formSelect('id_quymocongty',$this->Item['id_quymocongty'], array('style'=>'width:256px;'), $this->slbQuyMoCTKH);
	$id_linhvuchoatdong		= $this->cmsSelect('id_linhvuchoatdong',$this->Item['id_linhvuchoatdong'],$this->slbLinhVucHDKH,array('size'=>0, 'style'=>'width:256px;'));
	$id_loaihinhcongty		= $this->cmsSelect('id_loaihinhcongty',$this->Item['id_loaihinhcongty'],$this->slbLoaiHinhCTKH,array('size'=>0, 'style'=>'width:256px;'));
	$id_phongban			= $this->cmsSelect('id_phongban',$this->Item['id_phongban'],$this->slbPhongBan,array('size'=>0, 'style'=>'width:256px;', 'onChange' => 'show_manager(' . $id_phongban. ', '. $nhanvien .')'));
	$id_nhanvien			= $this->formSelect('id_nhanvien',$this->Item['id_nhanvien'], array('style'=>'width:256px;'), $this->slbNhanVien);
	
	//-------------------- SESSAGES ERROR ------------------
	if (count($this->messageError)>0) {
		$errors = $this->formErrors($this->messageError, array('class'=>'thongbaoError goc5'));
		
		foreach ($this->messageError AS $key => $val){
			echo '<div class="listError" id="'.$key.'" rel="' . $val . '"></div>';
		}
	}
	
?>

<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
</div>

<div class="right_content">
	<div class="appContent">
		<form name="appForm" method="post" action="" enctype="multipart/form-data">
			<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
			<?php
				//-------------------- SESSAGES ERROR ------------------
				if(count($this->messageError)>0){
					foreach ($this->messageError AS $key => $val){
						echo '<div class="listError" data="'.$key.'" rel="' . $val . '"></div>';
					}
					echo '<div class="thongbaoError goc5">Có lỗi trong quá trình xử lý.</div>';
				} 
			?>
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">Thông tin chung</a></li>
				</ul>
				<div id="tabs-1">
					<div class="tblForm">
						<div class="tbl_title">Thông tin chung</div>
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Tên khách hàng <span class="star">*</span></td>
									<td><?php echo $name; ?></td>
									<td class="label">Tên viết tắt</td>
									<td><?php echo $tenviettat; ?></td>
								</tr>
								<tr>
									<td class="label">Điện thoại di động</td>
									<td><?php echo $phone; ?></td>
									<td class="label">Email</td>
									<td><?php echo $email; ?></td>
								</tr>
								<tr>
									<td class="label">Ghi chú</td>
									<td colspan="3"><?php echo $note; ?></td>
								</tr>
								<tr>
									<td class="label">Mã số thuế</td>
									<td><?php echo $masothue; ?></td>
									<td class="label">Năm thành lập</td>
									<td><?php echo $namthanhlap; ?></td>
								</tr>
								<tr>
									<td class="label">Số ĐKKD</td>
									<td><?php echo $sodkkd;?></td>
									<td class="label">Ngày kỉ niệm</td>
									<td><?php echo $ngaykiniem; ?></td>
								</tr>
							</table>
						</div>
						<div class="tbl_title">Trụ sở chính</div>
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Địa chỉ</td>
									<td><?php echo $address; ?></td>
									<td class="label">Quốc gia</td>
									<td><?php echo $id_country; ?></td>
								</tr>
								<tr>
									<td class="label">Điện thoại cố định</td>
									<td><?php echo $telephone; ?></td>
									<td class="label">Tỉnh thành</td>
									<td>
										<div id="city">
											<?php echo $id_city; ?>
										</div>
									</td>
								</tr>
								
								<tr>
									<td class="label">Fax</td>
									<td><?php echo $fax; ?></td>
									
									<td class="label">Quận huyện</td>
									<td>
										<div id="district">
											<?php echo $id_district; ?>
										</div>
									</td>
								</tr>
								
								<tr>
									<td class="label">Website</td>
									<td><?php echo $website; ?></td>
									<td class="label">Ghi chú</td>
									<td rowspan="2"><?php echo $ghichu; ?></td>
								</tr>
							</table>
						</div>
						
						<script>
								$(window).load(function(){
									show_cities(<?php echo $country;?> , <?php echo $city; ?>, <?php echo $district; ?>);
									show_manager(<?php echo $id_phongbans; ?>, <?php echo $nhanvien; ?>);
								});	
						
								function show_districts(id_country, id_city, id_district) {
									var index = $('#id_city').val();									
									var url = '<?php echo $this->baseUrl('default/ajax/load-districts/id_city/') ?>' + index;
									$.post(url, {'id_country' : id_country, 'id_district' : id_district}, function(data) {
										$('#district').html(data);
									});
								}
							
								function show_cities(id_country, id_city, id_district) {
									var index = $('#id_country').val();
									var url = '<?php echo $this->baseUrl('default/ajax/load-cities/id_country/') ?>' + index;
									$.post(url, {'id_city' : id_city, 'id_district' : id_district}, function(data) {
										$('#city').html(data);
										show_districts(id_country, id_city, id_district, id_city);
									});
								}

								function show_manager(id_phongban, id_nhanvien) {
									var index = $('#id_phongban').val();
									var url = '<?php echo $this->baseUrl('default/ajax/load-managers/id_phongban/') ?>' + index;
									$.post(url, {'id_nhanvien' : id_nhanvien}, function(data) {
										$('#manager').html(data);
									});
								}
						</script>
						
						<div class="tbl_title">Phân loại khách hàng</div>
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Biết đến từ</td>
									<td><?php echo $id_nguon; ?></td>
									<td class="label">Nhu cầu sản phẩm</td>
									<td rowspan="2">
										<div class="divChonManager" id="divChonKhoahoc" style="height: 50px;">
										<?php
											if(!empty($this->Item['id_khoahoc'])){
												foreach ($this->Item['id_khoahoc'] AS $key => $val){
													echo '<span class="item goc3" id="'.$this->Khoahoc[$val]['id'].'">'.$this->Khoahoc[$val]['name'].'<a href="javascript:void(0)" class="delete" title="Xóa" onclick="xoaMotKhoahoc('.$this->Khoahoc[$val]['id'].', \'divChonKhoahoc\')"></a></span>';
													echo '<input id="'.$this->Khoahoc[$val]['id'].'" type="hidden" name="id_khoahoc[]" value="'.$this->Khoahoc[$val]['id'].'">';
												}
											} 
										?>
										</div>
										<a onclick="showListKhoahoc('divChonKhoahoc', 'id_khoahoc')" href="javascript:void(0)" class="showListManager" id="showListKhoahoc">Show</a>
										<a onclick="xoaTrangDiv('divChonKhoahoc')" href="javascript:void(0)" class="deleteListManager">Delete</a>
									</td>
								</tr>
								
								<tr>
									<td class="label">Khách hàng đăng ký từ</td>
									<td><?php echo $id_nguon_dk; ?></td>
								</tr>
								
								<tr>
									<td class="label">Phân loại khách hàng</td>
									<td><?php echo $status_tiemnang; ?></td>
									
								</tr>
								
								<tr>
									<td class="label">Quy mô công ty</td>
									<td><?php echo $id_quymocongty; ?></td>
								</tr>
								<tr>
									<td class="label">Số lượng nhân viên</td>
									<td><?php echo $tongsolaodong; ?></td>
								</tr>
								<tr>
									<td class="label">Lĩnh vực hoạt động</td>
									<td><?php echo $id_linhvuchoatdong; ?></td>
								</tr>
								<tr>
									<td class="label">Loại hình công ty</td>
									<td><?php echo $id_loaihinhcongty; ?></td>
								</tr>
							</table>
							
						</div>
						
						<div class="tbl_title">Thông tin quản lý</div>
						<div class="tbl_content">
							<table class="tbl">
								<tr>
									<td class="label">Đơn vị quản lý <span class="star">*</span></td>
									<td>
										<?php echo $id_phongban; ?>
										<div class="view_error" id="view_id_phongban"></div>
									</td>
									<td class="label">Người quản lý <span class="star">*</span></td>
									<td>
										<span id="manager">
											<?php echo $id_nhanvien; ?>
										</span>
										<div class="view_error" id="view_id_nhanvien"></div>
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
			<!-- END: 	CONTENT -->
		</form>	
	</div>	
</div>
<div class="clr"></div>
